package top.tupobi.zing.custom_view;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zyyoona7.popup.BasePopup;

import java.util.List;

import top.tupobi.zing.R;
import top.tupobi.zing.adapter.AdapterRvFriendApplyList;
import top.tupobi.zing.listener.OnFriendApplyResult;
import top.tupobi.zing.mvp.model.FriendApply;

public class FriendApplyListPop extends BasePopup<FriendApplyListPop> {

    private Context mContext;
    private List<FriendApply> mInvites;
    private AdapterRvFriendApplyList mAdapterRvFriendApplyList;

    public void setOnFriendApplyResult(OnFriendApplyResult onFriendApplyResult) {
        mAdapterRvFriendApplyList.setOnFriendApplyResult(onFriendApplyResult);
    }

    public static FriendApplyListPop create(Context context, List<FriendApply> invites) {
        return new FriendApplyListPop(context, invites);
    }

    private FriendApplyListPop(Context context, List<FriendApply> invites) {
        mContext = context;
        mInvites = invites;
        setContext(context);//注意这一行，没有会崩！！

        mAdapterRvFriendApplyList = new AdapterRvFriendApplyList(context);
    }

    @Override
    protected void initAttributes() {
        setContentView(R.layout.popwindow_friend_apply_list, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        setFocusAndOutsideEnable(true)
                .setBackgroundDimEnable(true)
                .setDimValue(0.5f);
    }

    @Override
    protected void initViews(View view, FriendApplyListPop pop) {
        RecyclerView rv_friend_apply_list = view.findViewById(R.id.rv_friend_apply_list);
        rv_friend_apply_list.setLayoutManager(new LinearLayoutManager(mContext));
        rv_friend_apply_list.setAdapter(mAdapterRvFriendApplyList);
        mAdapterRvFriendApplyList.notifyApplyListChanged(mInvites);
    }
}
